package org.grow.present;

import org.grow.present.properties.CommonProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.nio.file.Files;
import java.nio.file.Path;


// Generated by https://start.springboot.io
// 优质的 spring/boot/data/security/cloud 框架中文文档尽在 => https://springdoc.cn
@SpringBootApplication
@EnableScheduling
@EnableConfigurationProperties({CommonProperties.class})
public class PresentApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(PresentApplication.class, args);
    }

    @Value("${present.common.image-location}")
    private String location;

    @Override
    public void run(String... args) throws Exception {
        if (location == null) {
            System.out.println("载入静态目录失败");
        } else {

            System.out.println("载入静态目录成功" + location);
            Path l = Path.of(location);
            boolean exists = Files.exists(l);
            if (!exists) {
                System.out.println("查询静态目录失败" + location+"请于配置文件中设好静态资源目录");
            } else {
                System.out.println("查询静态目录成功" + location);
                Path t = l.resolve("temp");
                if (Files.notExists(t)) {
                    Files.createDirectories(l.resolve("temp"));
                }
            }
        }
    }
}
